package at.guigu.controller;

import at.guigu.pojo.Brand;
import at.guigu.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

// @RestController = @Controller+ @ResponseBody
@RestController
// Restful风格
@RequestMapping(value = "/brands")
public class BrandController {
    @Autowired
    private BrandService brandService;
    // 查询所有数据
    @GetMapping
    public List<Brand> getAll() {
        return brandService.getAll();
    }

    // 查询单条数据：通过id查询
    @GetMapping("/{id}")
    public Brand getById(@PathVariable(value = "id") Integer id) {
        return brandService.getById(id);
    }
    // 静态单条件查询
    @GetMapping("/singleConOne/{id}")
    public List<Brand> selectBySingleConOne(@PathVariable(value = "id") Integer id) {
        return brandService.selectBySingleConOne(id);
    }
    // 动态单条件查询——对象参数接收
    @GetMapping("/singleConTwo")
    public List<Brand> selectBySingleConTwo(@RequestParam("brandName") String brandName, @RequestParam("companyName") String companyName,
                                            @RequestParam("ordered") Integer ordered,@RequestParam("description") String description,
                                            @RequestParam("status") Integer status) {
        Brand brand = new Brand();
        brand.setBrandName(brandName);
        brand.setCompanyName(companyName);
        brand.setOrdered(ordered);
        brand.setDescription(description);
        brand.setStatus(status);
        return brandService.selectBySingleConTwo(brand);
    }
    // 动态单条件查询——Map集合参数接收
    @GetMapping("/singleConTwoo")
    public List<Brand> selectBySingleConTwoo(@RequestParam("map") Map map) {
        return brandService.selectBySingleConTwoo(map);
    }
    // 动态多条件查询——对象参数接收
    @GetMapping("/maxConOne")
    public List<Brand> selectByMaxConOne(@RequestParam("brandName") String brandName, @RequestParam("companyName") String companyName,
                                         @RequestParam("ordered") Integer ordered,@RequestParam("description") String description,
                                         @RequestParam("status") Integer status) {
        Brand brand = new Brand();
        brand.setBrandName(brandName);
        brand.setCompanyName(companyName);
        brand.setOrdered(ordered);
        brand.setDescription(description);
        brand.setStatus(status);
        return brandService.selectByMaxConOne(brand);
    }
    // 动态多条件查询——Map集合参数接收
    @GetMapping("/maxConTwo")
    public List<Brand> selectByMaxConTwo(@RequestParam("map") Map map) {
        return brandService.selectByMaxConTwo(map);
    }
}
